﻿/**
 *    Copyright 2012 Yohan Courbe
 *
 *  Licensed under the Apache License, Version 2.0 (the "License") 
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *      
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

using System;
using System.Drawing;
using System.Windows.Forms;

namespace NetworkAnalyzer.Engines.Graphics.HttpHits
{
    class HttpHit
    {
        public readonly string Domain;
        public readonly PointF Point;
        public readonly String Font;
        public readonly Color Color;

        public float Activity = 1;

        private static readonly string[] Fonts = {
                                            "Arial", 
                                            "Arial Black", 
                                            "Times New Roman", 
                                            "Calibri",
                                            "Consolas"
                                        };

        private static readonly Color[] Colors = {
                                            Color.FromArgb(0x1732FE), 
                                            Color.FromArgb(0x1732FE), 
                                            Color.FromArgb(0x1833FE), 
                                            Color.FromArgb(0x3A4DDB),
                                            Color.FromArgb(0x5D68B8)
                                        };

        public HttpHit(string domain)
        {
            Domain = domain;

            // Give random point

            var rand = new Random();

            Point = new PointF(rand.Next(0, Screen.PrimaryScreen.Bounds.Width - 50), rand.Next(0, Screen.PrimaryScreen.Bounds.Height - 10));

            Font = Fonts[rand.Next(0, Fonts.Length - 1)];
            Color = Colors[rand.Next(0, Colors.Length - 1)];

            Console.WriteLine("new hit {0} {1} {2} {3}", Domain, Point, Font, Color);
        }

        public float CalculateFontSize()
        {
            return Activity;
        }

        public void IncreaseActivity()
        {
            Activity *= 1.25f;

            if (Activity > 50)
            {
                Activity = 50;
            }
        }

        public void DecreaseActivity()
        {
            Activity *= 0.99f;

            if (Activity < 1)
            {
                Activity = 1;
            }
        }
    }
}